package com.douyu.ocean.serversCheck;

import java.util.List;


public class CheckHBaseRegion extends ServerCheck {

	private String host;
	
	public CheckHBaseRegion(String host){
		this.host = host;
	}
	
	@Override
	public String checkHealth() {
		log.info("checking with hbase region server at :" + this.host);
		String warning_message = "";
		String[] shellArgs  = new String[]{this.host};
		String fileName = "check.sh";
		
		List<String> res = RunShellFile.runFile(fileName, shellArgs);
		boolean isChecked = false; 
		log.info("ran shell file and return size : "+ res.size());
		if(res.size() > 0){
			for(String item : res){
				if(item.contains("HRegionServer")){
					isChecked = true;
					break;
				}
			}
			
			if(!isChecked){
				warning_message = "RS died at : "+ this.host;
				log.warn(warning_message);
			}
		}else{
			log.error("run shell file error when checking hbase region");
		}
		
		if(warning_message.isEmpty())
			log.info("checked hbase region server");
		else
			log.error("hbase region server down!");
		
		return warning_message;
	}
	
	public static void main(String[] args){
		CheckHBaseRegion tmp = new CheckHBaseRegion("172.16.253.128");
		tmp.checkHealth();
	}
}
